package com.zzyl.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.DeviceDataPageReqDto;
import com.zzyl.mapper.DeviceDataMapper;
import com.zzyl.service.DeviceDataService;
import com.zzyl.vo.DeviceDataVo;
import com.zzyl.vo.FloorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeviceDataServiceImpl implements DeviceDataService {

    @Autowired
    private DeviceDataMapper deviceDataMapper;
    @Override
    public PageResponse<DeviceDataVo> getPage(DeviceDataPageReqDto deviceDataPageReqDto) {
        LocalDateTime localDateTimeStart = LocalDateTimeUtil.of(deviceDataPageReqDto.getStartTime());
        LocalDateTime localDateTimeEnd = LocalDateTimeUtil.of(deviceDataPageReqDto.getEndTime());
        deviceDataPageReqDto.setStartDate(localDateTimeStart);
        deviceDataPageReqDto.setEndDate(localDateTimeEnd);

        PageHelper.startPage(deviceDataPageReqDto.getPageNum(),deviceDataPageReqDto.getPageSize());
        Page<DeviceDataVo> page = deviceDataMapper.getPage(deviceDataPageReqDto);

        return PageResponse.of(page, DeviceDataVo.class);
    }

//    @Override
//    public List<FloorVo> getAllFloorWithDevice() {
//        List<FloorVo> list = deviceDataMapper.getAllFloorWithDevice();
//        return list;
//    }
}























